
let data={};

/**
 * 全局数据存放区
 * 数据键值不能是‘clear’
 * 示例：
 *      RuntimeData.a=10;                   设置a->{a:10}
 *      RuntimeData.b=5;                    设置b->{a:10,b:5}
 *      RuntimeData.a+=1;                   a的取值及赋值->{a:11,b:5}
 *      let v=RuntimeData.a+RuntimeData.b;  取值->v=16
 *      RuntimeData.clear='a';              删除a->{b:5}
 *      RuntimeData.clear;                  删除所有->{}
 */
let RuntimeData=new Proxy(data,{
    set:(target,key,value)=> {
        if(key==='clear'){
            for(let k in target){
                if(value===k){
                    delete target[''+k+''];
                }
            }
        }else{
            target[key]=value;
        }
        return true;
    },
    get:(target,key)=>{
        if(key==='clear'){
            for(let key in target){
                delete target[''+key+''];
            }
            return null;
        }else{
            if(!target.hasOwnProperty(key)){
                console.warn('there is no data with key:[' + key + '] yet!');
                return null;
            }
            return target[key];
        }
    }
});

export default RuntimeData;